package edu.berkeley.cs160.innovationers.shoppersidekick;

import java.util.ArrayList;

import android.app.Activity;
import android.app.Application;


/***
 * 
 * 
 * @author Kenny Liou
 * This application is used to communicate everything in the "shoppers' sidekick"
 * This class can be used to store temp data, list data, global data, etc...
 * This way is more organized and clean for future development.
 * 
 * The idea is this class will exist when the app lunches. 
 * Every activity can get this object by calling getApplication()
 * The return value of getApplication() is an Application, which you should cast it into myApp
 * All activity under the same app will get the same myApp object. 
 * So a good practice is before an activity is closing, store all the necessary data on myApp
 * the main activity can then grab the data from myApp
 * 
 */
public class myApp extends Application {
	//Here are some global data
	private ArrayList<Member> myMemberList;
	private ArrayList<ShoppingList> myShoppingList;
	private Activity currentActivity;
	private ArrayList<Member> localMemberList;
	private boolean checkList = false;
	private String ListName;
	private String userName;
	private String C2DMUser="yorkethegod@gmail.com";
	private String serverIP = "";
	private boolean logIn = false;
	
	//Here are some variables
	final static int noChange = 2;
	final static int addList = 10;
	final static int newList = 11;
	final static int listView = 20;
	final static int listChanged = 21;
	final static int editMember = 30;
	final static int memberChanged = 31;
	final static int newItem = 40;
	final static int addItem = 41;
	final static int renameList = 50;
	final static int listNameChanged = 51;
	final static int login = 60;
	
	
	
	//Here are some method to modify the variables
	public void setListName(String name) {
		ListName=name;
	}
	public String getListName() {
		return ListName;
	}
	public void setCurrentActivity(Activity myApp){
		currentActivity = myApp;	
	}
	public void setShoppingList(ArrayList<ShoppingList> newList){
		myShoppingList = newList;
	}
	public void setMemberList(ArrayList<Member> myMem){
		myMemberList = myMem;
	}
	
	public void addShoppingList(ShoppingList ToAdd) {
		myShoppingList.add(ToAdd);
	}
	
	public ArrayList<Member> getMemberList(){
		return myMemberList;
	}
	public int getMemberCount(){
		return myMemberList.size();
	}
	public ArrayList<ShoppingList> getShoppingList(){
		return myShoppingList;
	}
	public void setUserName(String n){
		userName = n;
		logIn = true;
	}
	

	//Here are some data that is used in between activities
	private int currentListPosition;
	
	public int getPosition(){
		return currentListPosition;
	}
	public void setPosition(int c){
		currentListPosition = c;
	}
	public void setLocalMemberList(ArrayList<Member> mList){
		localMemberList = mList;
	}
	public ArrayList<Member> getLocalMemberList(){
		return localMemberList;
	}
	public boolean isCheckList(){
		return checkList;
	}
	public void setCheckList(boolean t){
		checkList = t;
	}
	public String getUserName(){
		return userName;
	}
	public String getServerIP(){
		return serverIP;
	}
	public boolean isLogin(){
		return logIn;
	}

	public ShoppingList findList(String name){
		for(int i = 0; i < myShoppingList.size(); i++)
			if(myShoppingList.get(i).getName().equals(name))
				return myShoppingList.get(i);
		return null;
	}
	
	public String getC2DMUser(){
		return C2DMUser;
	}
	
	public void setC2DMUser(String name) {
		C2DMUser=name;
	}
}
